#ifndef YEARTIMELINE_H
#define YEARTIMELINE_H
#include <iostream>
#include <QtCore>
#include <QDebug>
#include <QCoreApplication>
#include <QObject>
#include "TimeStructure.h"
#include "ui_calendario_occupazioni.h"

#include <QtGui>
#include <QDate>

#define _BG_ \
         QString( "#ffffff")
         
#define _CG_ \
         QString( "#000000")

///////typedef QMap<int,CAnno> AnniFatti;

#include <QtCore>
#include <QDebug>
#include <QCoreApplication>
#include <QObject>
#include "TimeStructure.h"
#include <QTableWidget>
#include <QAbstractItemModel>

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QGridLayout>
#include <QtGui/QPushButton>
#include <QtGui/QSpacerItem>
#include <QtGui/QTextEdit>




class Ui_EditComment
{
public:
    QGridLayout *gridLayout;
    QTextEdit *textEdit;
    QSpacerItem *spacerItem;
    QPushButton *pushButton_2;
    QPushButton *pushButton;

    void setupUi(QWidget *EditComment)
    {
    if (EditComment->objectName().isEmpty())
        EditComment->setObjectName(QString::fromUtf8("EditComment"));
    EditComment->resize(300, 170);
    EditComment->setMaximumSize(QSize(300, 170));
    gridLayout = new QGridLayout(EditComment);
    gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
    textEdit = new QTextEdit(EditComment);
    textEdit->setObjectName(QString::fromUtf8("textEdit"));
    textEdit->setWindowModality(Qt::ApplicationModal);

    gridLayout->addWidget(textEdit, 0, 0, 1, 3);

    spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);

    gridLayout->addItem(spacerItem, 1, 0, 1, 1);

    pushButton_2 = new QPushButton(EditComment);
    pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));

    gridLayout->addWidget(pushButton_2, 1, 1, 1, 1);

    pushButton = new QPushButton(EditComment);
    pushButton->setObjectName(QString::fromUtf8("pushButton"));

    gridLayout->addWidget(pushButton, 1, 2, 1, 1);


    retranslateUi(EditComment);
    QObject::connect(pushButton_2, SIGNAL(clicked()), EditComment, SLOT(close()));
    ////////////////QObject::connect(pushButton, SIGNAL(clicked()), EditComment, SLOT(reject()));

    QMetaObject::connectSlotsByName(EditComment);
    } // setupUi

    void retranslateUi(QWidget *EditComment)
    {
    EditComment->setWindowTitle(QApplication::translate("EditComment", "La vostre note. (Mas. 255 battute)", 0, QApplication::UnicodeUTF8));
    pushButton_2->setText(QApplication::translate("EditComment", "Ok", 0, QApplication::UnicodeUTF8));
    pushButton->setText(QApplication::translate("EditComment", "Chiudi", 0, QApplication::UnicodeUTF8));
    Q_UNUSED(EditComment);
    } // retranslateUi

};

namespace Ui {
    class EditComment: public Ui_EditComment {};
} // namespace Ui



class EditComment : public QWidget, public Ui::EditComment
{
    Q_OBJECT
//
public:
 EditComment()
{
 setupUi( this );
 setWindowFlags(Qt::Popup);
}
void SetData( QString da ) {
  
    textEdit->clear();
    textEdit->setPlainText(da); 
}
protected:
public slots:
    
};





class CalendarHouses : public QTableWidget
{
	Q_OBJECT 
	
public:
	CalendarHouses( QWidget *parent = 0 );
  void OpenYear( CAnno anno );
  void OpenYear( const int y , int user  ); 
  inline int Anno() { return ANNOCORRENZE_INCORSO; }
  QString TakeConfig();
  protected:
	QFont bold_base_font;
  QFont hiden_font;
	void CreateRows( int owner , int y );
	void contextMenuEvent ( QContextMenuEvent * e );
	QStringList RTFmonth;
	bool Onloading;
	int ANNOCORRENZE_INCORSO;
	int User_id;
  void SetLine( CMonths M , const int row  );
  void SetCell( CDay d , const int cool ,  const int row  );
  int last_cools_active;
  QList<QTableWidgetItem *> selezioni;
	void FillModus( QList<QTableWidgetItem *> list , const int setmodus , bool readonly = false );
	int mysize();
	QList<QTableWidgetItem *> selector( const int riga );
	void save_data();
	QList<CDay> CurrentDayList;
	CAnno InCome;
  signals:
  public slots:
		void ActiveSelection();
	  void Notaday();
	  void ExportAsFile();
	  void ImportFromFile();
		void Riservati();
};


////////typedef QMap<int,CAnno> AnniFatti;




class Calendario_Occupazioni : public QDialog, public Ui::Calendario_Occupazioni
{
    Q_OBJECT
//
public:
 Calendario_Occupazioni( QWidget * parent = 0 )
{ 
 Load();
}
inline void Load()
{
 LoadingAction = true;
 User = 55;
 setupUi( this );
 QDate now = QDate::currentDate ();
 PlayAnno = now.year();
 qDebug() << " Calendario_Occupazioni  333 ";
 Anno->setRange ( now.year() - 1 , now.year() + 3 ); 
 Anno->setValue ( now.year() );
 qDebug() << " Calendario_Occupazioni  444 ";
 tabella = new CalendarHouses();
 tabella->OpenYear(PlayAnno,User);
 stackedWidget->addWidget(tabella);
 stackedWidget->setCurrentIndex(1); 
 ///////connect(Anno, SIGNAL(valueChanged(int)),this, SLOT(dateset(int)));
 label->setText(tabella->windowTitle());
 LoadingAction = false; 
}
protected:
  int User;
  bool LoadingAction;
  int PlayAnno;
  CalendarHouses *tabella;
  int NextMake;
  QList<CalendarHouses*> Ganni;
private:
signals:
public slots:
    void dateset( int d )
    {
        qDebug() << " TakeConfig call ";
        
            QString DD = tabella->TakeConfig();
            ////////qDebug() << " salva vecchio anno->" << d << " peso-validi->" << DD.size();
            if (DD.size() > 0) {
                
                ///////////////qDebug() << " salva vecchio si " << DD;
                
            } else {
                ///////qDebug() << " salva vecchio no ";
            }
            
               
            for (int i=0; i<Ganni.size(); i++) {
                if (Ganni[i]->Anno() == d) {
                    stackedWidget->setCurrentWidget ( Ganni[i] );
                    label->setText(Ganni[i]->windowTitle());
                    return;
                }
            }
            qDebug() << " crea nuova tabella   " << d;
            tabella = new CalendarHouses();
            tabella->OpenYear(d,User);
            Ganni.append(tabella);
            stackedWidget->addWidget(tabella);
            label->setText(tabella->windowTitle());
            
            
    }
};


























//
#endif // YEARTIMELINE_H
